package com.houweishi.module.adjustment.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.adjustment.domain.OaAdjustment;
import com.houweishi.module.adjustment.domain.OaAdjustmentApproval;
import com.houweishi.module.adjustment.service.IOaAdjustmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 职位，薪资申请单Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/adjustment")
public class OaAdjustmentController extends BaseController
{
    @Autowired
    private IOaAdjustmentService oaAdjustmentService;

    /**
     * 查询职位，薪资申请单列表
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaAdjustment oaAdjustment)
    {
        startPage();
        List<OaAdjustmentApproval> list = oaAdjustmentService.selectOaAdjustmentApprovalList(oaAdjustment);
        return getDataTable(list);
    }

    /**
     * 导出职位，薪资申请单列表
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:export')")
    @Log(title = "职位，薪资申请单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaAdjustment oaAdjustment)
    {
        List<OaAdjustment> list = oaAdjustmentService.selectOaAdjustmentList(oaAdjustment);
        ExcelUtil<OaAdjustment> util = new ExcelUtil<OaAdjustment>(OaAdjustment.class);
        util.exportExcel(response, list, "职位，薪资申请单数据");
    }

    /**
     * 获取职位，薪资申请单详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:query')")
    @GetMapping(value = "/{adjustmentId}")
    public AjaxResult getInfo(@PathVariable("adjustmentId") Long adjustmentId)
    {
        return success(oaAdjustmentService.selectOaAdjustmentByAdjustmentId(adjustmentId));
    }

    /**
     * 新增职位，薪资申请单
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:add')")
    @Log(title = "职位，薪资申请单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaAdjustment oaAdjustment)
    {
        try {
            return oaAdjustmentService.insertOaAdjustment(oaAdjustment);
        } catch (Exception e) {
            logger.error("新增职位，薪资申请单失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改职位，薪资申请单
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:edit')")
    @Log(title = "职位，薪资申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaAdjustment oaAdjustment)
    {
        return toAjax(oaAdjustmentService.updateOaAdjustment(oaAdjustment));
    }

    /**
     * 删除职位，薪资申请单
     */
    @PreAuthorize("@ss.hasPermi('module:adjustment:remove')")
    @Log(title = "职位，薪资申请单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{adjustmentIds}")
    public AjaxResult remove(@PathVariable Long[] adjustmentIds)
    {
        return toAjax(oaAdjustmentService.deleteOaAdjustmentByAdjustmentIds(adjustmentIds));
    }
}
